package com.ykt.mall.ctrl;

import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.ykt.mall.content.Content;
import com.ykt.model.Customer;
import com.ykt.model.Order;
import com.ykt.model.Shop;

@ControllerBind(controllerKey="/payOrders")//viewPath="/template"
public class PayOrderCtrl extends Controller {
	
	public void view(){
		
		int shopId = this.getParaToInt("shopId");
		Shop shop = Shop.dao.findById(shopId);
		int id = this.getParaToInt("id");
		Order po = Order.dao.findById(id);
		int payment=po.getInt("payment");
		
		this.setAttr("shopPo",shop);
		this.setAttr("po", po);
		
		Customer cus = getSessionAttr(Content.SESSION_LOGIN_USER);
		int frontSign = cus.getInt("front_sign")==null ? 0 : cus.getInt("front_sign");
		this.setAttr("frontSign", frontSign);
		
		if(payment==1 && frontSign!=1){
			po.set("status", 2);//状态改成等待
			po.update();
			setAttr("addr", po.getAddr());
			forwardAction("/payOrders/success");
			return;
		}
	}
	public void success(){
		
	}
	
	public void result(){
		
		int orderId = this.getParaToInt();
		
		Order o = Order.dao.findById(orderId);
		
		this.setAttr("order", o);
	}
	
	
}
